package com.pz.cloud.framework.base.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pz.cloud.framework.base.dao.CommonDao;
import com.pz.cloud.framework.util.SqlUtil;
import com.pz.cloud.framework.util.WorkflowUtil;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.dto.LogDTO;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.IPUtils;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.base.mapper.BaseCommonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class BaseServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M,T> implements IBaseService<T> {
    @Autowired
    protected CommonDao commonDao;
    @Override
    public boolean removeById(Serializable id) {
        WorkflowUtil.deleteProcess((String) id);
        return super.removeById(id);
    }

    @Override
    public boolean removeByIds(Collection<? extends Serializable> idList) {
        for (Serializable id : idList) {
            WorkflowUtil.deleteProcess((String) id);
        }
        return super.removeByIds(idList);
    }

    public boolean updateById(T entity, boolean updateNullColumn) {
        boolean b;
        if(updateNullColumn){
            Map<String,Object> parms = new HashMap<>();
            String updateSql = SqlUtil.createUpdateSql(entity, parms);
            b = commonDao.execute(updateSql,parms);
        }else{
             b = super.updateById(entity);
        }
        return b;
    }
}
